const { behavior } = require('miniprogram-computed')

export const swiperCellBehavior = Behavior({
  data: {
    swiperCellOpenQueue: []
  },
  methods: {
    onSwiperCellOpen(event) {
      const instance = this.selectComponent(`#${event.currentTarget.id}`)
      this.data.swiperCellOpenQueue.push(instance)
    },
    onSwiperCellClickPage() {
      this.onSwiperCellClickCommon()
    },
    onSwiperCellClick() {
      this.onSwiperCellClickCommon()
    },
    onSwiperCellClickCommon() {
      this.data.swiperCellOpenQueue.forEach((instance) => {
        instance.close()
      })
      this.setData({
        swipeCellOpenQueue: []
      })
    }
  }
})
